<template>
  <div>
    <!-- 面包屑导航 -->
    <breadcrumbs :data1="data1" :data2="data2"></breadcrumbs>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList" border stripe style="width: 100%">
        <el-table-column type="index" label="序号" width="70"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="400"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="order_pay" label="是否付款">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_pay == 0" size="medium" type="danger">未付款</el-tag>
            <el-tag v-else size="mini" type="success">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">{{scope.row.create_time | dateFormat}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <el-tooltip effect="light" content="更改收货地址" placement="top" :enterable="false">
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="editAddress"></el-button>
          </el-tooltip>
          <el-tooltip effect="light" content="查看物流信息" placement="top" :enterable="false">
            <el-button type="success" icon="el-icon-truck" size="mini" @click="lookwuliu"></el-button>
          </el-tooltip>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
      <el-dialog title="修改收货地址" :visible.sync="addressdialogVisible" width="50%" @close="closeForm">
        <el-form
          :model="addressForm"
          :rules="addressrules"
          ref="addressFormRef"
          label-width="100px"
        >
          <el-form-item label="省市区:" prop="address1">
            <el-cascader
              v-model="addressForm.address1"
              :options="cityData"
              :props="{ expandTrigger: 'hover' }"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址:" prop="address2">
            <el-input v-model="addressForm.address2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="addressdialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="addressdialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>

      <el-dialog title="物流信息" :visible.sync="wuliudialogVisible" width="50%">
        <el-timeline :reverse="false">
          <el-timeline-item
            v-for="(item, index) in wuliuInfo"
            :key="index"
            :timestamp="item.time" color= '#0bbd87'
          >{{item.context}}</el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>
           
<script>
import breadcrumbs from '@/common/breadcrumbs'
import cityData from './citydata.js'
export default {
  data () {
    return {
      data1: '订单管理',
      data2: '订单列表',
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      orderList: [],
      addressdialogVisible: false,
      wuliudialogVisible: false,
      cityData,
      addressForm: {
        address1: [],
        address2: ''
      },
      wuliuInfo: [],
      addressrules: {
        address1: [
          { required: true, message: '请选择省市区', trigger: 'blur' },
        ],
        address2: [
          { required: true, message: '请填写具体地址', trigger: 'blur' },
        ]
      }
    }
  },
  methods: {
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange (val) {
      this.queryInfo.pagesize = val
      this.getOrderList()
    },
    handleCurrentChange (val) {
      this.queryInfo.pagenum = val
      this.getOrderList()
    },
    editAddress () {
      this.addressdialogVisible = true
    },
    closeForm () {
      this.$refs.addressFormRef.resetFields()
    },
    async lookwuliu () {
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      this.wuliuInfo = res.data
      console.log(this.wuliuInfo);
      this.wuliudialogVisible = true
    }
  },
  created () {
    this.getOrderList()
  },
  components: {
    breadcrumbs
  }
}
</script>
<style scoped>
.el-cascader {
  width: 100%;
}
</style>